package com.taofuxn.yycreazy.mvp.presenter;

import com.taofuxn.yycreazy.mvp.BasePresenter;
import com.taofuxn.yycreazy.mvp.model.RandomJokBean;
import com.taofuxn.yycreazy.mvp.view.IRandomView;
import com.taofuxn.yycreazy.retrofit.ApiStore;
import com.taofuxn.yycreazy.retrofit.Key;
import com.taofuxn.yycreazy.rxjava.ApiCallback;
import com.taofuxn.yycreazy.rxjava.SubscriberCallback;

import java.util.HashMap;

/**
 * Created by wanghuafu on 16/9/17.
 */
public class RandomPresenter extends BasePresenter {
    private IRandomView mIRandomView;

    public RandomPresenter(IRandomView mIRandomView){
        this.mIRandomView = mIRandomView;
        onAttachView(mIRandomView);
    }

    public void loadData(final boolean isReflash, int curpage){

        HashMap<String, String> params = new HashMap<>();
        params.put("pagesize", "20");
        params.put("key", Key.jokey);
        addSubscription(mRetrofit.create(ApiStore.class).getRandomData("http://v.juhe.cn/joke/randJoke.php",Key.jokey,mIRandomView.getType()),new SubscriberCallback(new ApiCallback() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onFailed(int code, String msg) {

            }

            @Override
            public void onSuccess(Object o) {
                RandomJokBean response = (RandomJokBean) o;
                mIRandomView.dismissLoading();
                if (isReflash)
                    mIRandomView.reflashSuccess(response.result);
                else
                    mIRandomView.loadmoreSuccess(response.result);

            }
        }));

    }
}
